{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "84146ca7-626c-4872-a12e-00c4bb194f8f",
   "metadata": {},
   "outputs": [],
   "source": [
    "'''\n",
    "各城市python开发工程师一部分招聘数据，\n",
    "\n",
    "序号    城市    Python工程师岗位数    平均月薪\n",
    "1       武汉       1.2k              12.0k\n",
    "2       上海       7.9k              17.2k\n",
    "3       深圳       6.4k              16.8k\n",
    "4       广州       2.5k              12.8k\n",
    "5       苏州       910               12.8k\n",
    "6       南京       1.3k              13.3k\n",
    "7       成都       1.6k              11.6k\n",
    "8       北京       8.7k              19.2k\n",
    "9       杭州       2.5k              15.5k\n",
    "\n",
    "1.添加西安，岗位数664，平均月薪12.9k\n",
    "2.更改职位数和月薪的格式，去掉k改为数值\n",
    "3.按照月薪从高到低排序，输出前5名\n",
    "4.按照岗位数量排序，排出前5名\n",
    "\n",
    "'''"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "2c40821f-5922-4619-b91f-d78b906592cd",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 116,
   "id": "9dc8ddd7-4689-45c7-a9e7-7f52156dd835",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "#按照字典方式添加数据\n",
    "dict = {'城市':['武汉','上海','深圳','广州','苏州','南京','成都','北京','杭州'],\n",
    "        'Python岗位数':['1.2K','7.9k','6.4K','2.5K','910','1.3K','1.6K','8.7K','2.5K'],\n",
    "        '平均月薪':['12.0K','17.2K','16.8K','12.8K','12.8k','13.3K','11.6K','19.2K','15.5K']}\n",
    "df = pd.DataFrame(dict)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 100,
   "id": "9a5037e3-da98-4dce-9eaf-de93fa335594",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   城市 Python岗位数   平均月薪\n",
      "0  武汉      1.2K  12.0K\n",
      "1  上海      7.9k  17.2K\n",
      "2  深圳      6.4K  16.8K\n",
      "3  广州      2.5K  12.8K\n",
      "4  苏州       910  12.8k\n",
      "5  南京      1.3K  13.3K\n",
      "6  成都      1.6K  11.6K\n",
      "7  北京      8.7K  19.2K\n",
      "8  杭州      2.5K  15.5K\n"
     ]
    }
   ],
   "source": [
    "print(df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 117,
   "id": "948230db-be80-44ea-b8a4-d22f922650d8",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>城市</th>\n",
       "      <th>Python岗位数</th>\n",
       "      <th>平均月薪</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>武汉</td>\n",
       "      <td>1.2K</td>\n",
       "      <td>12.0K</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>上海</td>\n",
       "      <td>7.9k</td>\n",
       "      <td>17.2K</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>深圳</td>\n",
       "      <td>6.4K</td>\n",
       "      <td>16.8K</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>广州</td>\n",
       "      <td>2.5K</td>\n",
       "      <td>12.8K</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>苏州</td>\n",
       "      <td>910</td>\n",
       "      <td>12.8k</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>南京</td>\n",
       "      <td>1.3K</td>\n",
       "      <td>13.3K</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>成都</td>\n",
       "      <td>1.6K</td>\n",
       "      <td>11.6K</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>北京</td>\n",
       "      <td>8.7K</td>\n",
       "      <td>19.2K</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>杭州</td>\n",
       "      <td>2.5K</td>\n",
       "      <td>15.5K</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>西安</td>\n",
       "      <td>664</td>\n",
       "      <td>15.5k</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   城市 Python岗位数   平均月薪\n",
       "0  武汉      1.2K  12.0K\n",
       "1  上海      7.9k  17.2K\n",
       "2  深圳      6.4K  16.8K\n",
       "3  广州      2.5K  12.8K\n",
       "4  苏州       910  12.8k\n",
       "5  南京      1.3K  13.3K\n",
       "6  成都      1.6K  11.6K\n",
       "7  北京      8.7K  19.2K\n",
       "8  杭州      2.5K  15.5K\n",
       "9  西安       664  15.5k"
      ]
     },
     "execution_count": 117,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#1.添加西安，岗位数664，平均月薪12.9k  \n",
    "df.loc[9]=['西安','664','15.5k']  #！！！！！注意大小写\n",
    "\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 118,
   "id": "2942a67a-ca23-47f7-ae66-45036e53cb01",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   城市 Python岗位数   平均月薪\n",
      "0  武汉      1200  12.0K\n",
      "1  上海      7900  17.2K\n",
      "2  深圳      6400  16.8K\n",
      "3  广州      2500  12.8K\n",
      "4  苏州       910  12.8k\n",
      "5  南京      1300  13.3K\n",
      "6  成都      1600  11.6K\n",
      "7  北京      8700  19.2K\n",
      "8  杭州      2500  15.5K\n",
      "9  西安       664  15.5k\n"
     ]
    }
   ],
   "source": [
    "#2.更改职位数和月薪的格式，去掉k改为数值..！！！！注意k和K的大小写\n",
    "jobs = df['Python岗位数']\n",
    "for i in range(len(jobs)):\n",
    "    if type(jobs[i]) != int: \n",
    "        if 'K'in jobs[i] or 'k'in jobs[i]  :\n",
    "            jobs[i] = int( float(jobs[i].replace('K','').replace('k',''))*1000  ) \n",
    "        else:\n",
    "            jobs[i] = int(jobs[i])\n",
    "\n",
    "df['Python岗位数'] = jobs\n",
    "#智能运行一次，因为int(jobs[i])转换问题\n",
    "\n",
    "print(df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 121,
   "id": "59d6cbe8-c27e-4501-b700-0c957a7568fc",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   城市 Python岗位数   平均月薪\n",
      "0  武汉      1200  12000\n",
      "1  上海      7900  17200\n",
      "2  深圳      6400  16800\n",
      "3  广州      2500  12800\n",
      "4  苏州       910  12800\n",
      "5  南京      1300  13300\n",
      "6  成都      1600  11600\n",
      "7  北京      8700  19200\n",
      "8  杭州      2500  15500\n",
      "9  西安       664  15500\n"
     ]
    }
   ],
   "source": [
    "#2.更改月薪的格式，去掉k改为数值\n",
    "cash = df['平均月薪']\n",
    "\n",
    "for i in range(len(cash)):\n",
    "    if type(cash[i])!=int:\n",
    "        if 'K' in cash[i] or 'k' in cash[i]:\n",
    "            cash[i] = int( float(cash[i].replace('K',\"\").replace('k',''))*1000)\n",
    "        else:\n",
    "            cash[i] = int(cash[i])\n",
    "df['平均月薪'] = cash        \n",
    "print(df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "id": "a3f19e5c-036b-4c9c-993e-7bb3e1192963",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   城市 Python岗位数   平均月薪\n",
      "0  武汉      1200  12000\n",
      "1  上海      7900  17200\n",
      "2  深圳      6400  16800\n",
      "3  广州      2500  12800\n",
      "4  苏州       910  12800\n",
      "5  南京      1300  13300\n",
      "6  成都      1600  11600\n",
      "7  北京      8700  19200\n",
      "8  杭州      2500  15500\n",
      "9  西安       664  15500\n"
     ]
    }
   ],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 125,
   "id": "e9ce6eb3-e8a4-4b17-b3a0-d1d0f21522f9",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>城市</th>\n",
       "      <th>Python岗位数</th>\n",
       "      <th>平均月薪</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>北京</td>\n",
       "      <td>8700</td>\n",
       "      <td>19200</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>上海</td>\n",
       "      <td>7900</td>\n",
       "      <td>17200</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>深圳</td>\n",
       "      <td>6400</td>\n",
       "      <td>16800</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>杭州</td>\n",
       "      <td>2500</td>\n",
       "      <td>15500</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>西安</td>\n",
       "      <td>664</td>\n",
       "      <td>15500</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>南京</td>\n",
       "      <td>1300</td>\n",
       "      <td>13300</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>广州</td>\n",
       "      <td>2500</td>\n",
       "      <td>12800</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>苏州</td>\n",
       "      <td>910</td>\n",
       "      <td>12800</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>武汉</td>\n",
       "      <td>1200</td>\n",
       "      <td>12000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>成都</td>\n",
       "      <td>1600</td>\n",
       "      <td>11600</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   城市 Python岗位数   平均月薪\n",
       "7  北京      8700  19200\n",
       "1  上海      7900  17200\n",
       "2  深圳      6400  16800\n",
       "8  杭州      2500  15500\n",
       "9  西安       664  15500\n",
       "5  南京      1300  13300\n",
       "3  广州      2500  12800\n",
       "4  苏州       910  12800\n",
       "0  武汉      1200  12000\n",
       "6  成都      1600  11600"
      ]
     },
     "execution_count": 125,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#3.按照月薪从高到低排序，输出前5名\n",
    "df.sort_values('平均月薪',ascending=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 126,
   "id": "c225d421-5310-4799-a060-eae1ece067e6",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>城市</th>\n",
       "      <th>Python岗位数</th>\n",
       "      <th>平均月薪</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>北京</td>\n",
       "      <td>8700</td>\n",
       "      <td>19200</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>上海</td>\n",
       "      <td>7900</td>\n",
       "      <td>17200</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>深圳</td>\n",
       "      <td>6400</td>\n",
       "      <td>16800</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>杭州</td>\n",
       "      <td>2500</td>\n",
       "      <td>15500</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>西安</td>\n",
       "      <td>664</td>\n",
       "      <td>15500</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   城市 Python岗位数   平均月薪\n",
       "7  北京      8700  19200\n",
       "1  上海      7900  17200\n",
       "2  深圳      6400  16800\n",
       "8  杭州      2500  15500\n",
       "9  西安       664  15500"
      ]
     },
     "execution_count": 126,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.sort_values('平均月薪',ascending=False).head(5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 141,
   "id": "d5c793d9-e774-4f68-8cb3-99365b6870f3",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>城市</th>\n",
       "      <th>Python岗位数</th>\n",
       "      <th>平均月薪</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>北京</td>\n",
       "      <td>8700</td>\n",
       "      <td>19200</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>上海</td>\n",
       "      <td>7900</td>\n",
       "      <td>17200</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>深圳</td>\n",
       "      <td>6400</td>\n",
       "      <td>16800</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>广州</td>\n",
       "      <td>2500</td>\n",
       "      <td>12800</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>杭州</td>\n",
       "      <td>2500</td>\n",
       "      <td>15500</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>成都</td>\n",
       "      <td>1600</td>\n",
       "      <td>11600</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>南京</td>\n",
       "      <td>1300</td>\n",
       "      <td>13300</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>武汉</td>\n",
       "      <td>1200</td>\n",
       "      <td>12000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>苏州</td>\n",
       "      <td>910</td>\n",
       "      <td>12800</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>西安</td>\n",
       "      <td>664</td>\n",
       "      <td>15500</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   城市 Python岗位数   平均月薪\n",
       "7  北京      8700  19200\n",
       "1  上海      7900  17200\n",
       "2  深圳      6400  16800\n",
       "3  广州      2500  12800\n",
       "8  杭州      2500  15500\n",
       "6  成都      1600  11600\n",
       "5  南京      1300  13300\n",
       "0  武汉      1200  12000\n",
       "4  苏州       910  12800\n",
       "9  西安       664  15500"
      ]
     },
     "execution_count": 141,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#4.按照岗位数量排序，排出前5名\n",
    "df.sort_values('Python岗位数',ascending=False,inplace=True)  #这里加了inplace，运行时已经改了源数据\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 146,
   "id": "70fc0b19-25db-4266-98ee-aca2e8e17d74",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>城市</th>\n",
       "      <th>平均月薪</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>北京</td>\n",
       "      <td>19200</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>上海</td>\n",
       "      <td>17200</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>深圳</td>\n",
       "      <td>16800</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>广州</td>\n",
       "      <td>12800</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>杭州</td>\n",
       "      <td>15500</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   城市   平均月薪\n",
       "7  北京  19200\n",
       "1  上海  17200\n",
       "2  深圳  16800\n",
       "3  广州  12800\n",
       "8  杭州  15500"
      ]
     },
     "execution_count": 146,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc[:,['城市','平均月薪']].head(5) #因为前面已经inplace了，所以这里直接查询head(5)就可以了"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 161,
   "id": "5283b123-6673-4c01-93aa-82526954d998",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>城市</th>\n",
       "      <th>平均月薪</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>北京</td>\n",
       "      <td>19200</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>上海</td>\n",
       "      <td>17200</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>深圳</td>\n",
       "      <td>16800</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>广州</td>\n",
       "      <td>12800</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>杭州</td>\n",
       "      <td>15500</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>成都</td>\n",
       "      <td>11600</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>南京</td>\n",
       "      <td>13300</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>武汉</td>\n",
       "      <td>12000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>苏州</td>\n",
       "      <td>12800</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   城市   平均月薪\n",
       "7  北京  19200\n",
       "1  上海  17200\n",
       "2  深圳  16800\n",
       "3  广州  12800\n",
       "8  杭州  15500\n",
       "6  成都  11600\n",
       "5  南京  13300\n",
       "0  武汉  12000\n",
       "4  苏州  12800"
      ]
     },
     "execution_count": 161,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc[:4,['城市','平均月薪']] #  :4指的是从0到标签4的数据。因为标签顺序被打乱了，所以从0到4，中间隔着的数也会被遍历到"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e9b63a02-c240-4aad-ad61-9b1d857ee754",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
